Skip to main content

Easy ✔

  • To apply two pointer approach for sum problem, array need to be sorted, if not sorted use hash map.
  • Sub array sum are solved using HashTable(unordered_map), Some may solved by prefix sum.
  1. Largest Element
    • In Bruteforce, compare each item with other(O(n2n^2))
    • In Better, sort it descending order, first item is the answer(O(nlognnlog n))
    • In Optimal, single pass through array(O(n))
  2. Second Largest
  3. Check Rotated Sorted
    1. 20 March, 2026: 00.07.12 ✔
      • Identify the graph and check first and last item of the list
  4. Remove Duplicates
    1. 20 March, 2026: 00.03.18 ✔
  5. Left Rotate By One Place
  6. Left Rotate By D Place
    1. 20 March, 2026: 00.02.58 ❌
      • Failed at optimization
        • Bruite Force Trade-Off: Space O(N) vs Time O(N^2)
        • Optimal: Reverse 3 times(partion wise)
  7. Moves Zeros to end
    1. 20 March, 2026: 00.02.54 ✔
  8. Linear Search
  9. Find Union
    1. 20 March, 2026: 00.07.26 ❌
      • Failed at optimization
        • Handle the duplicate value issue
  10. Find Missing numbers
    • Brute force: find an element from an array with 2 loop, one is for iteration, other is to find that iterated item.
    • Bit Approach: xor of [0, n](xr^=i) vs xor of item of array
    • Math Approach: sum of [0, n](n*(n+1/2)) vs sum of item of array
  11. Maximum Consecutive Ones
  12. Find the number that appear once
  13. Sub Array Sum(K) - Positive
    1. 09 April, 2026: 00.19.01 ❌
      • Failed at optimization
        • Bruteforce: O(n2)O(n^2), Prefix Sum: O(n2)O(n^2), Hash Table: O(n)O(n), Sliding Window: O(n)O(n)
        • Subbary can be formed in multiple element, so don't just check and perform incerement, decrement, store the previous value then check and perform incerement, decrement
  14. Length of Sub Array Sum(K)
    1. 09 April, 2026: 00.26.20 ❌
      • Failed at implmentation
        • Handle the case where forward element doesn't make any effect like 0 0 0 or -2 2 4 -4
        • Sliding window fail for negative number, because during shrinking it perform some unpredictable behavour(- - = +)
  15. Length of largest sub array with 0 sum
    1. 09 April, 2026: 00.01.20 ✔